package com.terrier.ui.skins.skinBaseClasses
{
    import com.terrier.ui.skins.IWxButtonSkin;
    import com.terrier.ui.skins.WxFlaSkinUtility;

    import flash.display.DisplayObject;
    import flash.display.Sprite;

    public class WxButtonSkinBase implements IWxButtonSkin
    {
        protected var _upBg:DisplayObject;

        protected var _overBg:DisplayObject;

        protected var _downBg:DisplayObject;

        protected var _disabledBg:DisplayObject;

        public function WxButtonSkinBase()
        {

        }

        public function get upBg():DisplayObject
        {
            return _upBg;
        }

        public function get overBg():DisplayObject
        {
            return _overBg;
        }

        public function get downBg():DisplayObject
        {
            return _downBg;
        }

        public function get disabledBg():DisplayObject
        {
            return _disabledBg;
        }

        public function get width():Number
        {
            return _upBg != null ? _upBg.width : 0;
        }

        public function set width(value:Number):void
        {
            _upBg != null ? _upBg.width = value : null;
            _overBg != null ? _overBg.width = value : null;
            _downBg != null ? _downBg.width = value : null;
            _disabledBg != null ? _disabledBg.width = value : null;
        }

        public function get height():Number
        {
            return _upBg != null ? _upBg.height : 0;
        }

        public function set height(value:Number):void
        {
            _upBg != null ? _upBg.height = value : null;
            _overBg != null ? _overBg.height = value : null;
            _downBg != null ? _downBg.height = value : null;
            _disabledBg != null ? _disabledBg.height = value : null;
        }

        public function get customLayout():Boolean
        {
            return false;
        }

        public function initByAsset(asset:Sprite):void
        {
            if (asset == null || asset.numChildren == 0)
            {
                return;
            }
            var bgAsset:Sprite = asset.getChildAt(0) as Sprite;
            _upBg = WxFlaSkinUtility.getDisplayObject(bgAsset, 1);
            _overBg = WxFlaSkinUtility.getDisplayObject(bgAsset, 2);
            _downBg = WxFlaSkinUtility.getDisplayObject(bgAsset, 3);
            _disabledBg = WxFlaSkinUtility.getDisplayObject(bgAsset, 4);
        }
    }
}
